package com.hxx.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class DbManager {
	//单例模式
	private DbManager(){}
	private static DbManager db = new DbManager();
	public static DbManager getInstance(){
		return db;
	}
	public Connection getConnection(){
		Connection con = null;
		Properties props = new Properties();
		try {
			props.load(Thread.currentThread().getContextClassLoader()
					.getResourceAsStream("jdbc.properties"));
			Class.forName(props.getProperty("driver"));
			con = DriverManager
                .getConnection(
						props.getProperty("url"),
						props.getProperty("user"),
						props.getProperty("password"));
		} catch (Exception e) {
			System.out.println("数据库连接失败");
			e.printStackTrace();
		}
		return con;
	}
}